using FireStarterModeller.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Base;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestDMUniqueContraintEditorControl
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
            
        }

        private static IControlFactory GetControlFactory()
        {
            return GlobalUIRegistry.ControlFactory;
        }

        [Test]
        public void TestMainLayout()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            DMUniqueConstraintEditorControl DMUniqueConstraintEditorControl = new DMUniqueConstraintEditorControl(GetControlFactory());
            //---------------Test Result -----------------------
            Assert.AreEqual(2, DMUniqueConstraintEditorControl.Controls.Count);
            Assert.IsInstanceOf(typeof(DMUniqueConstraintPropertiesControl), DMUniqueConstraintEditorControl.Controls[0]);
            Assert.IsNotNull(DMUniqueConstraintEditorControl.DetailPanelInfo);
        }

        [Test]
        public void TestDetailPanelLayout()
        {
            //---------------Execute Test ----------------------
            DMUniqueConstraintEditorControl DMUniqueConstraintEditorControl = new DMUniqueConstraintEditorControl(GetControlFactory());
 
            //---------------Test Result --------------------------
            IPanelInfo panelInfo = DMUniqueConstraintEditorControl.DetailPanelInfo;
            Assert.IsNotNull(panelInfo);
            PanelInfo.FieldInfoCollection mappers = panelInfo.FieldInfos;
            Assert.IsNotNull(mappers);
            Assert.IsInstanceOf(typeof(ITextBox), mappers["Message"].ControlMapper.Control);
            ITextBox messageTextBox = (ITextBox) mappers["Message"].ControlMapper.Control;
            Assert.IsTrue(messageTextBox.Multiline);
        }

        [Test]
        public void TestBusinessObjectIsSameAsOneInPanelInfo()
        {
            //---------------Set up test pack-------------------
            DMUniqueConstraintEditorControl DMUniqueConstraintEditorControl = new DMUniqueConstraintEditorControl(GetControlFactory());
            //---------------Assert Precondition----------------
            Assert.AreEqual(DMUniqueConstraintEditorControl.BusinessObject, DMUniqueConstraintEditorControl.DetailPanelInfo.BusinessObject);
            Assert.AreEqual(DMUniqueConstraintEditorControl.BusinessObject, DMUniqueConstraintEditorControl.PropertiesControl.BusinessObject);
            //---------------Execute Test ----------------------
            DMUniqueConstraint newBO = new DMUniqueConstraint();
            DMUniqueConstraintEditorControl.BusinessObject = newBO;
            //---------------Test Result -----------------------
            Assert.AreSame(newBO, DMUniqueConstraintEditorControl.BusinessObject);
            Assert.AreSame(newBO, DMUniqueConstraintEditorControl.DetailPanelInfo.BusinessObject);
            Assert.AreSame(newBO, DMUniqueConstraintEditorControl.PropertiesControl.BusinessObject);

        }

   }
}